<template>
	<view>
		<view class="calendar-content" v-if="showCalendar">
			<view>
				<!-- 插入模式 -->
				<uni-calendar class="uni-calendar--hook" :selected="info.selected" showMonth />
			</view>
			<uni-calendar ref="calendar" class="uni-calendar--hook" :clear-date="true" :date="info.date"
				:insert="info.insert" :lunar="info.lunar" :startDate="info.startDate" :endDate="info.endDate"
				:range="info.range" />
			<view class="qianDao">
				<image src="../../static/images/qd.png" mode="" @click="qiandao()"></image>
			</view>
		</view>
	</view>
</template>
<script>
	function getDate(date, AddDayCount = 0) {
		if (!date) {
			date = new Date()
		}
		if (typeof date !== 'object') {
			date = date.replace(/-/g, '/')
		}
		const dd = new Date(date)

		dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期

		const y = dd.getFullYear()
		const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期，不足10补0
		const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号，不足10补0
		return {
			fullDate: y + '-' + m + '-' + d,
			year: y,
			month: m,
			date: d,
			day: dd.getDay()
		}
	}

	export default {
		data() {
			return {
				showCalendar: false,
				info: {
					lunar: true,
					range: true,
					insert: false,
					selected: []
				}
			}
		},
		onReady() {
			this.$nextTick(() => {
				this.showCalendar = true
			})

		},
		methods: {
			open() {
				this.$refs.calendar.open()
			},
			qiandao() {
				this.info.selected = [{
					date: getDate(new Date()).fullDate,
					info: '签到',
					data: {
						custom: '自定义信息',
						name: '自定义消息头'
					}
				}]
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #FFFFFF;
	}

	.example-body {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
	}

	.calendar-button {
		flex: 1;
		font-weight: bold;
		font-size: 32rpx;
	}

	.qianDao {
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.qianDao>image {
		width: 150rpx;
		height: 150rpx;
	}
</style>
